                package org.kealinghornets.nxtdroid;

import org.kealinghornets.nxtdroid.NXT.LightSensor;
import org.kealinghornets.nxtdroid.NXT.NXTThread;
import org.kealinghornets.nxtdroid.NXT.TouchSensor;

/**
 * Created by jychuah on 11/3/13.
 */
public class MyNXTThread extends NXTThread {

    int state = 1;
    LightSensor eyeball;

    public MyNXTThread() {
        setNXTThreadName("Bridge Crosser");
    }

    public void run() {
        while (state != -1) {
            switch(state) {
                case 1 : do_state_1(); break;
                case 2 : do_state_2(); break;
                case 3 : do_state_3(); break;
                default : state = -1; break;
            }
        }
    }

    public void do_state_1() {
        eyeball = getActiveLightSensor(PORT_1);
        int lightValue=0;
        log("I am in state 1");
        runMotor(PORT_A, -90);
        runMotor(PORT_B, 90);
        wait(1100);
        brakeMotor(PORT_A);
        brakeMotor(PORT_B);
        lightValue=eyeball.getLightValue();
        if (lightValue > 500) {
            state = 2;
        } else {
            state = 3;
        }

    }

    public void do_state_2() {
        log("I am in state 1");
        runMotor(PORT_A,-90);
        runMotor(PORT_B,-90);
        wait(2000);
        brakeMotor(PORT_A);
        brakeMotor(PORT_B);
        wait(1000);
        runMotor(PORT_A, 90);
        runMotor(PORT_B,-90);
        wait(1100);
        brakeMotor(PORT_A);
        brakeMotor(PORT_B);
            state = 5;

            }
    public void do_state_3() {
        eyeball = getActiveLightSensor(PORT_1);
        int lightValue=0;
        log("I am in state 1");
        runMotor(PORT_A,-90);
        runMotor(PORT_B, 90);
        wait(1100);
        brakeMotor(PORT_A);
        brakeMotor(PORT_B);
        lightValue=eyeball.getLightValue();
        if (lightValue > 500) {
            state = 6;
        } else {
            state = 3;
        }

    }
    public void do_state_5() {
        log("I am in state 1");
        runMotor(PORT_A,-90);
        runMotor(PORT_B,-90);
        wait(5000);
        brakeMotor(PORT_A);
        brakeMotor(PORT_B);
            state = 8
}